package algorithm.leetcode.I601to800;

/**
 * 股票系列,含手续费
 * 两种状态互相转移,持有和不持有
 *
 */

public class Q714 {

    public int maxProfit(int[] prices, int fee) {
        int inHand = -prices[0] - fee, outHand = 0;

        for (int i = 0; i < prices.length; i++) {
            int lastInHand = inHand, lastOutHand = outHand;
            inHand = Math.max(lastInHand, lastOutHand-prices[i]-fee);
            outHand = Math.max(lastOutHand, lastInHand+prices[i]);
        }
        return outHand;
    }

}
